package com.haiyou.dc.string;

import org.apache.commons.text.StringSubstitutor;

import java.util.HashMap;
import java.util.Map;

/**
 * https://blog.csdn.net/zhaoxj_2017/article/details/92839873
 * String 工具之StrSubstitutor, 字符替换
 */
public class TestStringSubstitutor {

    public static void main(String[] args) {
        Map valuesMap = new HashMap();
        valuesMap.put("animal", "quick brown fox");
        valuesMap.put("target", "lazy dog");
        valuesMap.put("xx", "lazeey dog");
        String templateString = "The ${animal} jumped over the ${target}.";
        String replace1 = new StringSubstitutor(valuesMap).replace(templateString);
        System.out.println(replace1);


        String template="你的订单号是：#{orderNo}，研究员名称：#{reacherName}";
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("orderNo","123456");
        hashMap.put("reacherName","张三");
        String replace = new StringSubstitutor(hashMap, "#{", "}", '#').replace(template);
        System.out.println(replace);

    }
}
